import React from 'react'
import { RouteRawState } from '../../router/routes'
import { useAppSelector } from '../../store'
import { Navigate } from 'react-router-dom'
interface PropsType {
  v: RouteRawState
}

export const BeforeEach: React.FC<PropsType> = ({v}) => {
  const token = useAppSelector(state => state.user.token)
  if(token || v.path === '/login') {
    return <div>{v.element}</div>
  }
  else {
    return <Navigate to="/login"></Navigate>
  }
}